package com.io.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.io.dto.UserListReq;
import com.io.entity.one2many.UserEntity;
import com.io.repository.TeacherDaoI;
import com.io.vo.ApiResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * The class/interface
 *
 * @author guodd
 * @version 1.0 use jdk 1.8
 */
@RestController
@Api(tags = "教师信息")
public class UserController {
    @Autowired
    private TeacherDaoI teacherDaoI;

    @GetMapping(value = "/getUser")
    public ApiResult test() {
        List<UserEntity> byAgeAfter = teacherDaoI.findByAgeAfter(12);
        UserEntity byFirstNameAndLastName = teacherDaoI.findByFirstNameAndLastName("aa", "bb");
        UserEntity byLastNameOrFirstName = teacherDaoI.findByLastNameOrFirstName("aa", "bb");
        UserEntity aa = teacherDaoI.findByFirstName("aa");
        UserEntity name = teacherDaoI.findByFirstNameLike("name");
        String playUrls = teacherDaoI.getPlayUrls("1");
        return ApiResult.ok(byAgeAfter);
    }

    @PostMapping(value = "/addUsers")
    public ApiResult addUser(UserListReq userListReq) throws JsonProcessingException {
        PageRequest of = PageRequest.of(0, 10);
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(userListReq);
        System.out.println(json);
        return ApiResult.ok();
    }
}
